<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    public function mergeIdcard(){
        $address = model('app\api\model\OrderAddress')->where([
            'idcard_front' => ['<>',''],
            'idcard_reverse' => ['<>',''],
            'idcard_merge' => null
        ])->limit(1)->select();
        $data = [];
        $time = time();
        foreach ($address as $a){

            if($a['idcard_front'] && $a['idcard_reverse'] && !$a['idcard_merge']){
                $idcard = model('app\api\model\Address')->mergeIdcard($a);
                $data[] = [
                    'id' => $a['id'],
                    'idcard_merge' => $idcard
                ];
            }
            echo time() - $time.'秒<br>';
            $time = time();
        }
        model('app\api\model\OrderAddress')->saveAll($data);
        echo 'success';
    }

    public function test(){
        $list = Db::name('express_package')->where('batch_id',15)->column('order_id');
        $list = Db::name('express_order_address')->where('order_id','in',$list)->select();
$i = 0;
        foreach ($list as $value){
            if(empty($value['idcard_merge'])){
                $i++;
            }
        }

        dump($i);
    }

    //修改密码
    public function pwd(){
        $password = "123456";
        $salt = "FRBTXU";
        $pwd = md5(md5($password) .$salt);
        echo $pwd;die;
    }

}
